package com.widevision.ListActivity;
//Hello its my comment
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;

import net.widevision.android.R;
import net.widevision.android.TwitterApp;
import twitter4j.ResponseList;
import twitter4j.User;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.widevision.adapter.FollowerListAdapter;

public class FollowerName extends Activity
{
	
	public static final String FOLLR_ID = "fr_id";
	public static final String FOLLR_NAME = "follr_name";
	public static final String FOLLR_THUMB_URL = "follr_thumb_url";
	private static final String twitter_consumer_key = "JXmXcE5yFPLIRCCtQ79eg";
	private static final String twitter_secret_key = "dnVojAwaewvEt8E2QwLYtavwm8cdUHwph7lZCaQPMY";
	
    FollowerListAdapter follrListAdapter;
	
    ArrayList<HashMap<String, String>> follrList = new ArrayList<HashMap<String, String>>();
    
   
    
    ResponseList<twitter4j.User> followerlisttext;
    
    User user,user1;
    
    TwitterApp mTwitter;
    
    InputStream is;
    
    Drawable followersimg;
    
    ListView followerlistview;
    
    TextView Scroll;
    
    String followername,screeName;
    
    int Userid,Id,id,count;
    
    String userId,userid;
    
    	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.followerlist);
		
		followerlistview    =(ListView) findViewById(R.id.frndidlist);
		Scroll              =(TextView) findViewById(R.id.scroller1);
       
		Bundle bundle=getIntent().getExtras();
			
		Userid=bundle.getInt("USERID");

		prepareArralist();
		
		follrListAdapter  = new FollowerListAdapter(FollowerName.this, follrList);
		followerlistview.setAdapter(follrListAdapter);
		
		Scroll.setSelected(true);
		
		Scroll.setText("@"+screeName+"'s Followers"+"                                                      ");
		
		followerlistview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int position,long arg3)
			{
				TextView txt = (TextView) view.findViewById(R.id.userId);
				userid=txt.getText().toString();
			    Intent intent=new Intent(FollowerName.this, UserProfile.class);
			    id=Integer.parseInt(userid);
			    intent.putExtra("USERID", id);
			    startActivity(intent);
			}
		});
	}

	private void prepareArralist()
	{
		
		    mTwitter 	= new TwitterApp(this, twitter_consumer_key,twitter_secret_key);
		    
			if (mTwitter.hasAccessToken()){
				
			user=mTwitter.showUser(Userid);
			
			screeName=user.getScreenName();
			
			count=user.getFollowersCount();
			
			followerlisttext=mTwitter.Followerids(Userid);
			
			try {
					for(int i=0;i<count;i++)
					{
						HashMap<String, String> map1 = new HashMap<String, String>();
						
						user1=followerlisttext.get(i);
				
						Id=user1.getId();
				
						userId=String.valueOf(Id);
						map1.put(FOLLR_ID,userId);
				
						followername=user1.getScreenName();
						map1.put(FOLLR_NAME,followername);
			
						URL u=user1.getProfileImageURL();
				
//						try
//						{
//							is = u.openStream();
//						}
//						catch (IOException e)
//						{
//							e.printStackTrace();
//						}
//					
//						followersimg = Drawable.createFromStream(is, "src name");
				
						map1.put(FOLLR_THUMB_URL,""+u);
						follrList.add(map1);

										
					}
			} 
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
	}

	
  }
